import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/routes/call/controller/xindong_call_rtc_controller.dart';
import 'package:xindong/routes/call/view/xindong_call_rtc_video_small_view.dart';
import 'package:xindong/utils/xindong_text_util.dart';

// 1v1 视频层
class XinDongCallRTCVideoPreview extends StatelessWidget {
  const XinDongCallRTCVideoPreview({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        GetBuilder<XinDongCallRTCController>(builder: (controller) {
          return Container(
            child: controller.isMineBigVideoWindow ? controller.mineVideoView : controller.targetVideoView,
          );
        }),

        // 对方视频有效显示提示 （停止直播直接关闭页面）
        GetBuilder<XinDongCallRTCController>(
          builder: (controller) {
            String text = "";
            if (!controller.isSmallShowTargetVideo) {
              if (controller.targetFirstVideoFrame == false) {
                text = "等待接收对方画面";
              } else if (controller.targetVideoAvailable == false) {
                text = "接收不到对方画面\n对方或许关闭了摄像头";
              }
            } else {
              if (controller.isCameraOff) {
                text = "已关闭摄像头";
              }
            }
            return TextUtil.isEmpty(text)
                ? const SizedBox()
                : Container(
                    alignment: Alignment.center,
                    child: Text(
                      text,
                      textAlign: TextAlign.center,
                      style: const TextStyle(fontSize: 15, color: Colors.white70),
                    ),
                  );
          },
        ),
      ],
    );
  }
}
